<?php

namespace RedMVC\Drawing\Color;
use RedMVC;

/**
 * Rgb class
 *
 * @category    RedMVC
 * @package     Drawing 
 * @subpackage  Color 
 * @author      Jan Fischer, bitWorking <info@bitworking.de>
 */
class Rgb{

    public $r;
    public $g;
    public $b;
    
    public function __construct($r, $g, $b){
        $this->r = min(max($r, 0), 255);
        $this->g = min(max($g, 0), 255);
        $this->b = min(max($b, 0), 255);
    }
    
    public static function normalize(Rgb $rgb){
        $self = new self($rgb->r / 255, $rgb->g / 255, $rgb->b / 255);
        return $self;
    }
    
    public function __toString(){
        return 'rgb('.$this->r.','.$this->g.','.$this->b.')';
    }
    
    public function toHex(){
        return RedMVC\Drawing\Color::rgb2hex($this);
    }
}